
//已经翻开的用1表示,未翻开的用2表示,雷用-1表示
//内置第2行的第3列(2,3) 和 第3行的第4列(3,4)为累
import java.util.Scanner;

public class SaoLeiAPP {
    static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int[][] a = new int[6][6];

        //是否被翻开
        int[][] b = new int[6][6];

        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                a[i][j] = 0;
            }
        }

        //初始化雷
        initLei(a);

        for (int i = 0; i < b.length; i++) {
            for (int j = 0; j < b[i].length; j++) {
                b[i][j] = 2;
            }
        }
        for (int i = 1; i < a.length-1; i++) {
            for (int j = 1; j < a[i].length-1; j++) {
                if((i==2&&j==3)||(i==3&&j==4)){
                    continue;
                }

                int lei=0;
                if(a[i][j-1] == -1)
                    lei++;
                if(a[i][j+1] == -1)
                    lei++;
                if(a[i-1][j] == -1)
                    lei++;
                if(a[i+1][j] == -1)
                    lei++;
                if(a[i-1][j-1] == -1)
                    lei++;
                if(a[i-1][j+1] == -1)
                    lei++;
                if(a[i+1][j-1] == -1)
                    lei++;
                if(a[i+1][j+1] == -1)
                    lei++;
                a[i][j] = lei;
            }
        }


        show(a,b);
        int n = 0;
        while (true){
            if(n==(4*4-2)){
                System.out.println("通关!");
                break;
            }
            System.out.println("请输入行号和列号(空格相隔):");
            int h = scanner.nextInt();
            int l = scanner.nextInt();
            if((h==2&&l==3)||(h==3&&l==4)){
                System.out.println("触发到了雷，失败!");
                break;
            }
            b[h][l] = 1;

            n++;
            show(a,b);
        }


    }
    static void initLei(int[][] lei){
        lei[2][3] = -1;
        lei[3][4] = -1;

    }
    static void show(int[][] a,int[][] b){
        for (int i = 1; i < b.length-1; i++) {
            for (int j = 1; j < b[i].length-1; j++) {
                if(b[i][j]==1){
                    System.out.print(a[i][j]+" ");
                }else {
                    System.out.print("? ");
                }

            }
            System.out.println();
        }
    }
}
